package petAppium;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.android.AndroidTouchAction;
import io.appium.java_client.touch.LongPressOptions;
import io.appium.java_client.touch.offset.ElementOption;

public class BaseDriver {
	public AndroidDriver<AndroidElement> driver = null;
	String urlStr = "http://127.0.0.1:4723/wd/hub";

	@BeforeClass
	public void initApp() throws MalformedURLException {
		URL url = new URL(urlStr);
		DesiredCapabilities cap = new DesiredCapabilities();

		cap.setCapability("platformName", "Android");
		cap.setCapability("deviceName", "8KE0220214005485");
		;
		cap.setCapability("appPackage", "com.example.petwithlove");
		cap.setCapability("appActivity", ".login.PasswordLogin");
		driver = new AndroidDriver<AndroidElement>(url, cap);

	}

	public void longPress(MobileElement item) {
		AndroidTouchAction action = new AndroidTouchAction(driver);
		LongPressOptions longPress = LongPressOptions.longPressOptions();
		longPress.withElement(ElementOption.element(item));
		action.longPress(longPress).release().perform();
	}

//	@AfterClass
//	public void quitApp() {
//		if (driver != null) {
//			driver.quit();
//		}
//
//	}

}
